package cn.wolfcode.service.impl;

import cn.wolfcode.domain.ExamEmployee;
import cn.wolfcode.mapper.ExamEmployeeMapper;
import cn.wolfcode.qo.QueryObject;
import cn.wolfcode.service.IExamEmployeeService;
import cn.wolfcode.util.UserContextUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class ExamEmployeeServiceImpl implements IExamEmployeeService {

    @Autowired
    private ExamEmployeeMapper examEmployeeMapper;


    @Override
    public void save(ExamEmployee examEmployee) {
        examEmployeeMapper.insert(examEmployee);
    }

    @Override
    public void delete(Long id) {
        examEmployeeMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void update(ExamEmployee examEmployee) {
        examEmployeeMapper.updateByPrimaryKey(examEmployee);
    }

    @Override
    public ExamEmployee get(Long id) {
        return examEmployeeMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<ExamEmployee> listAll() {
        return examEmployeeMapper.selectAll();
    }

    @Override
    public PageInfo<ExamEmployee> query(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize()); //对下一句sql进行自动分页
        List<ExamEmployee> examEmployees = examEmployeeMapper.selectForList(qo); //里面不需要自己写limit
        return new PageInfo<ExamEmployee>(examEmployees);
    }

    @Override
    public void commitExam(ExamEmployee examEmployee) {
        examEmployee.setCommitTime(new Date());
        examEmployee.setEmployee(UserContextUtil.getCurrentEmployee());
        examEmployeeMapper.insert(examEmployee);
    }
}
